﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace VFTray
{
	public partial class WndDebug : Form
	{
		UiUtility.SwitchButtonWindows switchBtnWnds = new UiUtility.SwitchButtonWindows();
		public WndDebug()
		{
			InitializeComponent();
			TopLevel = false;
			FormClosing += (s, e) =>
			  {
				  try
				  {
					  switchBtnWnds.Close();
				  }
				  catch (Exception ex)
				  {
					  LogUtility.LOG.Error("WndManual_FormClosing", ex);
				  }
			  };
		}

		//List<WndManualTray> forms = new List<WndManualTray>();
		List<string> names = new List<string>();
		List<int> authes = new List<int>();

		private WndDebugComServer wndDebugSvr = new WndDebugComServer();
		private WndDebug1 wndDebug = new WndDebug1();
		internal void Init()
		{
			//forms = new List<WndManualTray>();
			var wndforms = new List<Form>();

			names = new List<string>();
			authes = new List<int>();
			//foreach (var f in GlobalParams.PC.Feeders)
			//{
			//	forms.Add(new WndManualTray() { Feed = f });
			//	wndforms.Add(forms.Last());
			//	names.Add(f.GetCfgFeed().Name);
			//	authes.Add(f.GetCfgFeed().AuthUI);
			//}

			wndforms.Add(wndDebugSvr);
			names.Add("通信");
			authes.Add(30);

			wndforms.Add(wndDebug);
			names.Add("调试1");
			authes.Add(30);

			flowLayoutPanel1.BackColor = Color.MediumAquamarine;
			switchBtnWnds.ButtonSize = new Size(114, 45);
			switchBtnWnds.ButtonFontSize = 10.0F;
			switchBtnWnds.ButtonBold = true;
			switchBtnWnds.Add(wndforms.ToArray(), names.ToArray(), authes.ToArray(), tableLayoutPanel1, 0, 0, flowLayoutPanel1);
			switchBtnWnds.UpdateAuth(GlobalParams.Auth);
			switchBtnWnds.ShowWnd(0);

		}

		internal void OnUiTimer()
		{
			if (!Visible) return;
			try
			{
				//foreach(var f in forms)
				//{
				//	f.OnUiTimer();
				//}
				wndDebugSvr.OnUiTimer();
				wndDebug.OnUiTimer();
			}
			catch (Exception ex)
			{
				LogUtility.LOG.Error("WndManual.OnUiTimer", ex);
			}
		}

		internal void UpdateAuth()
		{
			switchBtnWnds.UpdateAuth(GlobalParams.Auth);
		}
	}
}
